package a630wj.recycleview630wj.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import a630wj.recycleview630wj.adapter.MyAdapter;
import a630wj.recycleview630wj.R;
import a630wj.recycleview630wj.bean.ArticleBean;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter myAdapter;
    private List<ArticleBean> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        //创建默认的线性LayoutManager
        layoutManager=new LinearLayoutManager(this);
        //设置布局
        recyclerView.setLayoutManager(layoutManager);
        //设置item 的高度
        recyclerView.setHasFixedSize(true);
        //创建适配器
        list=getData();
        myAdapter=new MyAdapter(this);
        myAdapter.setList(list);
        recyclerView.setAdapter(myAdapter);

      }

    public List<ArticleBean> getData() {
        List<ArticleBean>list=new ArrayList<ArticleBean>();
        ArticleBean article;
        article=new ArticleBean();
        article.setArticledId(1);
        article.setTitle("标题1");
        article.setImgid(R.drawable.f1);
        article.setTime("2017.5.4");
        article.setDescription("描述1");
        list.add(article);

        article=new ArticleBean();
        article.setArticledId(2);
        article.setTitle("标题2");
        article.setImgid(R.drawable.f2);
        article.setTime("2017.5.5");
        article.setDescription("描述2");
        list.add(article);

        article=new ArticleBean();
        article.setArticledId(3);
        article.setTitle("标题3");
        article.setImgid(R.drawable.f3);
        article.setTime("2017.5.6");
        article.setDescription("描述3");
        list.add(article);

        article=new ArticleBean();
        article.setArticledId(4);
        article.setTitle("标题4");
        article.setImgid(R.drawable.f4);
        article.setTime("2017.5.7");
        article.setDescription("描述4");
        list.add(article);

        article=new ArticleBean();
        article.setArticledId(5);
        article.setTitle("标题5");
        article.setImgid(R.drawable.f5);
        article.setTime("2017.5.8");
        article.setDescription("描述5");
        list.add(article);

        article=new ArticleBean();
        article.setArticledId(6);
        article.setTitle("标题6");
        article.setImgid(R.drawable.f6);
        article.setTime("2017.5.9");
        article.setDescription("描述6");
        list.add(article);
        return list;
    }
}
